﻿using System;
using System.Xml;
using System.Threading;
using System.IO;

namespace VS4CRM.Lib
{
    internal class EntityFile
    {
        public string TargetPath;
        public AutoResetEvent Event;
        
        private FileInfo _file = null;
        public XmlNode EntityXml { get; set;}
        
        #region EntityName
        string _entityName;
        public string EntityName
        {
            get 
            {
                if (_entityName == null && this.EntityXml != null)
                    _entityName = this.EntityXml.SelectSingleNode("EntityInfo/entity/@Name").Value;
                return _entityName;
            }
            set { _entityName = value; }
        }
        public FileInfo File
        {
            get
            {
                if (_file == null)
                {
                    _file = new FileInfo(string.Format("{0}\\{1}.xml", TargetPath, EntityName));
                }
                return _file;
            }
        }
        #endregion
    }

    internal class WorkflowFile
    {
        public string TargetPath;
        public AutoResetEvent Event;

        private FileInfo _file = null;
        public XmlNode WorkflowXml { get; set; }

        #region Name
        string _name;
        Guid _id;
        public string Name
        {
            get
            {
                if (_name == null && this.WorkflowXml != null)
                    _name = this.WorkflowXml.SelectSingleNode("@name").Value;
                return _name;
            }
            set { _name = value; }
        }

        public Guid ID
        {
            get
            {
                if ((_id ==null ||_id == Guid.Empty) && this.WorkflowXml != null)
                    _id = new Guid(this.WorkflowXml.SelectSingleNode("@workflowid").Value);
                return _id;
            }
            set { _id = value; }
        }

        public FileInfo File
        {
            get
            {
                if (_file == null)
                {
                    _file = new FileInfo(string.Format("{0}\\{1}.xml", TargetPath, Name));
                }
                return _file;
            }
        }
        #endregion
    }
}
